package bo;

import boerrors.EmployeInexistantException;
import java.rmi.RemoteException;
import java.util.Vector;
import run.PublisherImpl;

public class ListeEmployesInterne extends PublisherImpl{
        private static ListeEmployesInterne instance = null;
        private Vector<EmployeInterne> _listeEmployesInterne;

	//*******************************************************************
	//Constructeurs
	//*******************************************************************

        private ListeEmployesInterne() throws RemoteException{
                this._listeEmployesInterne = new Vector<EmployeInterne>();
        }  

       //*******************************************************************    
       //Constructeur du singleton    
       //******************************************************************* 
        
        public static ListeEmployesInterne getInstance() throws RemoteException{
                if(instance == null) 
                        instance = new ListeEmployesInterne();
                return instance;
        }    
            
	//*******************************************************************
	//Methodes
	//*******************************************************************        
        
        public synchronized Vector<EmployeInterne> rechercherEmployeInterne(String nom, String prenom) throws RemoteException {
                if ((nom != null)||(prenom != null)){
                        Vector<EmployeInterne> liste = new Vector<EmployeInterne>();
                        for (int i = 0 ; i < this._listeEmployesInterne.size() ; i++){
                        EmployeInterne employeInterne = this._listeEmployesInterne.get(i);
                            if ((employeInterne.getNom().compareTo(nom) == 0) && 
                                (employeInterne.getPrenom().compareTo(prenom) == 0)){
                            liste.add(employeInterne);
                            }
                        }
                return liste;
                }
                return null;
        }
    
        public synchronized EmployeInterne rechercherEmploye(int matricule) throws RemoteException, EmployeInexistantException {
                if (matricule > 0) {
                    for (int i = 0; i < this._listeEmployesInterne.size(); i++) {
                        EmployeInterne employeInterne = (EmployeInterne) this._listeEmployesInterne.get(i);
                        if (employeInterne.getMatricule() == matricule) {
                            return employeInterne;
                        }
                    }
                }
                throw new EmployeInexistantException();
        }

        public synchronized Vector<EmployeInterne> getListeEmployeInterne() throws RemoteException {
            return this._listeEmployesInterne;
        }
        
        public synchronized int nombreEmployesInterne() throws RemoteException {
            return this._listeEmployesInterne.size();
        }
        
        public synchronized void remplirListeEmployeInterne(Vector<EmployeInterne> emp) throws RemoteException {
            this._listeEmployesInterne = emp;
            this.notifyAllSubscibers();
        }
        
        public synchronized boolean ajouterEmployeInterne(EmployeInterne employe) throws RemoteException {
            if (employe == null) return false;
            if (instance._listeEmployesInterne.contains(employe)) return false;
            instance._listeEmployesInterne.add(employe);
            this.notifyAllSubscibers();
            return true;
        }
        
        public synchronized boolean supprimerEmployeInterne(EmployeInterne employe) throws RemoteException {
            if (employe == null) return false;
            if (instance._listeEmployesInterne.contains(employe)) return false;
            instance._listeEmployesInterne.remove(employe);
            this.notifyAllSubscibers();
            return true;
        }
}